<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
            <el-form-item label="手机号" prop="phoneNum">
                <el-input v-model="queryParams.phoneNum" placeholder="请输入手机号搜索" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-if="refreshTable" :data="menuList" row-key="menuId" :default-expand-all="isExpandAll"
            :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
            <el-table-column prop="wxId" label="用户id" ></el-table-column>
            <el-table-column prop="phoneNum" label="手机号" ></el-table-column>
            <el-table-column prop="name" label="用户姓名" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="appPurpose" label="申请用途"></el-table-column>
            <el-table-column label="审核状态">
                <template slot-scope="scope">
                    <span>{{ (scope.row.auditStatus === 0 ? '待审核' : scope.row.auditStatus === 1 ? '通过' :
                        scope.row.auditStatus ===2 ? '驳回' : '--') }}</span>
                </template>
            </el-table-column>
            <el-table-column prop="auditDesc" label="审核描述" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="certificationUrl" label="公函图片" >
                <template slot-scope="scope">
                    <el-image v-for="item in (scope.row.certificationUrl).split(',')" :key="item" style="width: 50px;height: 50px;" :src="item" :preview-src-list="scope.row.certificationUrl.split(',')"></el-image>
                </template>
            </el-table-column>
            <el-table-column label="气象证明" width="100" align="center">
                <template slot-scope="scope">
                    <div v-if="scope.row.resFileUrl.length">已开具，<a style="color: red;" :href="scope.row.resFileUrl">点击下载</a></div>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" fixed="right" width="120" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.auditStatus===0" @click="hanleEdit(scope.row)">审核</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete"
                        @click="handleDelete(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />
        <!-- 添加或修改菜单对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
            <el-form ref="form" :model="form" label-width="100px" v-loading="tableLoading">
                <el-form-item label="审核状态">
                    <el-radio-group v-model="form.auditStatus">
                        <el-radio label="1">通过</el-radio>
                        <el-radio label="2">驳回</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="审核意见">
                    <el-input type="textarea" v-model="form.auditDesc"></el-input>
                </el-form-item>
                <el-form-item label="气象证明" v-if="form.auditStatus==='1'">
                    <el-upload
                        accept=".pdf, .doc, .docx, .png, .jpg"
                        action="http://218.28.7.243:32201/common/files/upload"
                        :limit="1"
                        ref="upload"
                        :before-upload="beforeUpload"
                        :on-success="upSuccess"
                        :on-error="upError"
                        >
                        <el-button size="small" type="primary">
                            <span class="iconfont icon-shangchuan" />上传文件
                        </el-button>
                    </el-upload>
                    <span>上传文件只能是 pdf、doc、docx、png、jpg格式</span>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { orgWcertificateList, orgwcertificateAudit, orgwcertificateDel } from "@/api/login"

export default {
    name: "Menu",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 菜单表格树数据
            menuList: [],
            // 菜单树选项
            menuOptions: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 是否展开，默认全部折叠
            isExpandAll: false,
            // 重新渲染表格状态
            refreshTable: true,
            tableLoading: false, //修改时候的loading
            // 查询参数
            queryParams: {
                phoneNum: undefined,
                pageNum: 1,
                pageSize: 10,
            },
            total: 0,
            // 表单参数
            form: {
                auditDesc: '',
                auditStatus: '1'
            },
        }
    },
    created() {
        this.getList()
    },
    methods: {
        /** 查询菜单列表 */
        getList() {
            this.loading = true
            orgWcertificateList(this.queryParams).then(response => {
                this.menuList = response.data.pageData;
                this.total= response.data.totalCount;
                this.loading = false
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.$refs.upload.clearFiles();
            this.form = {
                id: undefined,
                auditStatus: '1',
                auditDesc: ''
            }
            this.resetForm("form")
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm")
            this.handleQuery()
        },
        /** 修改按钮操作 */
        hanleEdit(row) {
            this.form.id= row.id;
            this.open = true
            this.title = "审核"
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    orgwcertificateAudit(this.form).then(response => {
                        this.$modal.msgSuccess("审核完毕");
                        this.$refs.upload.clearFiles();
                        this.open = false
                        this.getList()
                    })
                }
            })
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            this.$modal.confirm('是否确认删除？').then(function () {
                return orgwcertificateDel({ids:row.id})
            }).then(() => {
                this.getList()
                this.$modal.msgSuccess("删除成功")
            }).catch(() => { })
        },
        // 上传文件
        beforeUpload(file) {
            // this.tableLoading= true;
        },
        // 上传成功
        upSuccess(e) {
            // this.tableLoading= false;
            this.form.fileUrl= e.data;
            this.$modal.msgSuccess("上传成功")
        },
        // 上传失败
        upError(e) {

        },
    }
}
</script>